using UnityEngine;
using System.Collections;

/// \class  gkShootInRhythmRequestFireInRhythm
/// \brief  Handle the request fire in rythm event
[AddComponentMenu("GK/ShootInRhythm/Fire/gkShootInRhythmRequestFireInRhythm")]
[RequireComponent(typeof(gkEventComponent))]
public class gkShootInRhythmRequestFireInRhythm : MonoBehaviour 
{	
	/// The shoot rhythm name 
	public string ShootRhythmName = "ShootRhythm";
		
	/// The rhythm synchroniser
	private gkRhythmSynchronizer m_rRhythmSynchronizer; 
	
	/// The event component
    private gkEventComponent m_rEventComponent;	
	
	/// \brief  Called before the first update
	void Start()
	{	
		// Grab the rhythm synchronizer
		m_rRhythmSynchronizer = GameObject.Find("RhythmSynchronizer").GetComponent<gkRhythmSynchronizer>();
	}
	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Grab event component
		m_rEventComponent = GetComponent<gkEventComponent>();
			
		// Listen the shock event of the owner
		m_rEventComponent.AddEventHandler(gkShootInRhythmFireEvent.RequestFireInRhythm, HandleFireInRhythmEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the shock event of the owner
		m_rEventComponent.RemoveEventHandler(gkShootInRhythmFireEvent.RequestFireInRhythm, HandleFireInRhythmEvent);
	}
	
	/// \brief  Handle the event
	void HandleFireInRhythmEvent(Object a_rEvent)
	{
		// Request the fire with the Rhythm synchronizer
		m_rRhythmSynchronizer.RaiseEventOnRythmStart(ShootRhythmName, m_rEventComponent, gkShootInRhythmFireEvent.StartFire);
	}
}
